package com.atwei.mango.system.securityHandler;

import com.atwei.mango.system.apiModel.response.ApiResponse;
import com.atwei.mango.system.exception.ResponseEnum;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Classname UserLoginFailureHandler
 * @Description 登陆失败处理类
 * @Date 2022/6/8 16:31
 * @Author liuwei
 */
@Component
public class UserLoginFailureHandler implements AuthenticationFailureHandler {
    @Override
    public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
        ApiResponse<Object> error = ApiResponse.error(ResponseEnum.LOGIN_FAILURE);
        error.setMsg(e.getMessage());
        ApiResponse.responseJson(httpServletResponse,error);
    }
}
